/************************************\
|* cardtest3.c                      *|
|* By Danny Burrows                 *|
|* burrowsd@onid.oregonstate.edu    *|
|* CS362 - Spring 2014              *|
|*                                  *|
|* Assignment 3                     *|
|*                                  *|
|* Unit testing of the adventurer   *|
|* card                             *|
\************************************/

#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include "dominion.h"

void checkTest(char *string, int before, int after)
{
	if (before == after)
		printf("FAIL - %s: before - %d, after - %d\n", string, before, after);
	else
		printf("PASS - %s: before - %d, after - %d\n", string, before, after);

	return;
}

void initGame(struct gameState *game)
{
	int *k = malloc(sizeof(int) * 10);
	int seed = rand() % (INT_MAX - 1) + 1;
	k = kingdomCards(0,1,2,3,4,5,6,7,8,9); // kindom cards required, if these values change, most of the tests fail
	initializeGame(2, k, seed, game); // must have an initialized game state

	return;
}

void runTests(struct gameState *game)
{
	/* int cardEffect(int card, int choice1, int choice2, int choice3, struct gameState *state, int handPos, int *bonus) */
	int currentPlayer = 0;
	int card = adventurer;
	int numTreasureHand = 0;
	int numTreasureAfter = 0;
	int deckCounter = game->deckCount[currentPlayer];
	for (int i = 0; i < game->handCount[currentPlayer]; ++i)
	{
		if (game->hand[currentPlayer][i] == copper || game->hand[currentPlayer][i] == silver || game->hand[currentPlayer][i] == gold)
			numTreasureHand++;
	}
	/* known that 7 of first 10 cards are treasure cards */
	/* adventurer card is supposed to add up to 2 treasure cards to the hand */
	cardEffect(adventurer, 0,0,0, game, 0, 0);
	for (int i = 0; i < game->handCount[currentPlayer]; ++i)
	{
		if (game->hand[currentPlayer][i] == copper || game->hand[currentPlayer][i] == silver || game->hand[currentPlayer][i] == gold)
			numTreasureAfter++;
	}
	checkTest("numTreasure", numTreasureHand, numTreasureAfter);
	cardEffect(adventurer, 0,0,0, game, 0, 0);
	numTreasureAfter = 0;
	for (int i = 0; i < game->handCount[currentPlayer]; ++i)
	{
		if (game->hand[currentPlayer][i] == copper || game->hand[currentPlayer][i] == silver || game->hand[currentPlayer][i] == gold)
			numTreasureAfter++;
	}
	checkTest("numTreasure", numTreasureHand, numTreasureAfter);

	return;
}

int main(int argc, char const *argv[])
{
	struct gameState *game = malloc(sizeof(struct gameState));

	initGame(game);
	
	runTests(game);

	free(game);

	return 0;
}